/*
Name: freshangle.funcs.js
Date: 12th July 2010
Version: 1.0
Description:     	
					
a 'last modified date' 											   

						
						
*/




/*--------------------------------------------------------------------------------------------------------------------------- */

/* 		 last modified date		www.google.com/support/forum/p/Chrome/thread?tid=37eb27384de9274c 		*/


/*--------------------------------------------------------------------------------------------------------------------------- */


function getLastModifiedDate() {
    var date = new Date(document.lastModified);

    // OPTIONS

    var day = 1; // Show the day, Yes = 1 No = 0
    var shortDay = 0; // Short Hand days, Yes = 1 No = 0 (you can't display 'shortDay' without 'day' set to 1!)	
    var shortMonth = 0; // Short Hand month, Yes = 1 No = 0 (the month is always displayed, but you can shorten it)	
    var year = 1; // Show the year, Yes = 1 No = 0	
    var time = 0; // Show the Time, Yes = 1 No = 0 (default setting is a 24 Hour Clock with no am/pm notifiers: 24HH:MM)
    var twhr = 0 // Show a 12 Hour Clock, Yes = 1 No = 0 (12 hour clock with am/pm notifiers: HH:MM AM/PM)
    var sec = 1 // Show the seconds, Yes = 1 No = 0 (24/12 hours as selected with seconds: HH:MM:SS) 


    // Ending for the day
    if (date.getDate() == 1 || date.getDate() == 21 || date.getDate() == 31) {
        var ending = "st";
    }
    else if (date.getDate() == 2 || date.getDate() == 22) {
        var ending = "nd";
    }
    else if (date.getDate() == 3 || date.getDate() == 23) {
        var ending = "rd";
    }
    else {
        var ending = "th";
    }

    // If you have Short Day on or off
    if (shortDay == 1) {
        var days = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
    }
    else {
        var days = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
    }

    // If you have Short Month on or off
    if (shortMonth == 1) {
        var month = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    }
    else {
        var month = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    }



    // If you have the time on
    if (time == 1) {
        var hour = date.getHours();
        var minute = date.getMinutes();
        var second = date.getSeconds();
        var ap = "";


        if (twhr == 1) {
            if (hour > 11) {
                ap = "PM";
            }
            else {
                ap = "AM";
            }
            if (hour > 12) {
                hour = hour - 12;
            }
            if (hour == 0) {
                hour = 12;
            }
            if (hour < 10) {
                hour = "0" + hour;
            }
        }

        if (minute < 10) {
            minute = "0" + minute;
        }
        if (second < 10) {
            second = "0" + second;
        }


        if (sec == 1) {
            var timeString = hour + ':' + minute + ':' + second + " " + ap;
        }
        else {
            var timeString = hour + ':' + minute + " " + ap;
        }
    }

    // Return the formatted last modified date/time

    if (day == 1) {
        day = (days[date.getDay()] + " "); // Saturday
        ending = (date.getDate() + ending + " "); // 29th			
    }
    else {
        day = " ";
        ending = " "
    }

    month = (month[date.getMonth()] + " "); // March


    if (year == 1) {
        year = (date.getFullYear()); // 2004
    }
    else {
        year = " ";
    }

    if (time == 1) {
        time = (" at " + timeString); // - 11:25:58 PM
    }
    else {
        time = " ";
    }

    return day + ending + month + year + time;
}


function showLastModifiedDate() {
    if (document.getElementById('lastModifiedDate') != null) {
        document.getElementById('lastModifiedDate').innerHTML = "Page last updated " + getLastModifiedDate();
    }
}




/*--------------------------------------------------------------------------------------------------------------------------- */

/*		call multiple onload events 	http://www.dyn-web.com/tutorials/combine.php */

/*--------------------------------------------------------------------------------------------------------------------------- */



addLoadEvent(showLastModifiedDate);

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function () {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}





